﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using BOMS.Utility;

namespace BOMS.WebUI.Web.PowerControl
{
    public partial class PowerControlProcess : System.Web.UI.Page
    {
        public string RDT
        {
            get { return Request.QueryString["rdt"]; }
        }
        public int ControlID { get { return int.Parse(Request.Params["id"]); } }
        public string isdealwith = "已处理";
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Model.PowerControl pid = (new BLL.PowerControl()).GetModel(ControlID);

                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    ShowInfo(ControlID);
                }

                string UserId = HttpContext.Current.User.Identity.Name;
                DataRow dr = GetUserRow(UserId);
                txtOperator.Text = dr["name"].ToString();
            }
        }
        private void ShowInfo(int ID)
        {
            BOMS.BLL.PowerControl bll = new BOMS.BLL.PowerControl();
            BOMS.Model.PowerControl model = bll.GetModel(ID);
            this.lblHostName.Text = model.HostName;
            this.lblPowerDownTime.Text = model.PowerDownTime.ToString();
            this.lblResDscTime.Text = RDT;
        }
        DataRow GetUserRow(string UserID)
        {
            DataRow dr = BOMS.DAL.SysAdmin.getUserInfoById(UserID).Rows[0];
            return dr;
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            BLL.PowerControl bll = new BLL.PowerControl();
            bll.UpdatePowerStatus(ControlID, isdealwith, RDT, DateTime.Now);
            Type cstype = this.GetType();
            ClientScript.RegisterStartupScript(cstype, "key", "dialogReturn('true');", true);
            ClientScript.RegisterStartupScript(cstype, "key", "dialogReturn('false');", true);
        }
    }
}